package com.example.bootdemo.tool;
import static com.example.bootdemo.BootdemoApplication.*;

import com.example.bootdemo.bean.Student;

import java.util.*;
//生成分类好的学生集合（Map实现
public class ClassifyStudents {
    public static Map<String,List<Student>> Classify(List<Student> students,Map<String,List<Student>> map){
        for (Student student : students) {
            String choiceSchool = student.getChoiceSchool();
            List<Student > lstUser;
            if (map.containsKey(choiceSchool)) {
                lstUser = map.get(choiceSchool);
            }else{
                lstUser= new ArrayList<>();
            }
            lstUser.add(student);
            map.put(choiceSchool,lstUser);
        }
//        Iterator<String> iterator = map.keySet().iterator();
//        for (Map.Entry<String, List<Student>> entry : map.entrySet()) {
//            result.add(entry.getValue());
//            schools.add(iterator.next());
//            //System.out.println(iterator.next());
////            for(Student student:entry.getValue()){
////                System.out.println("ID:"+Integer.parseInt(student.getStudentNumb())+"   "+"name:"+student.getStudentName()+"   "+"choiceSchool:"+student.getChoiceSchool());
////            }
//        }
//        for(List<Student> lists:result){
//            for(Student student:lists){
//                System.out.println("ID:"+student.getStudentNumb()+"   "+"name:"+student.getStudentName()+"   "+"choiceSchool:"+student.getChoiceSchool());
//            }
//        }
        //Iterator<String> iterator = map.keySet().iterator();
//        while (iterator.hasNext()){
//            //System.out.println("iterator:"+iterator.next());
//            schools.add(iterator.next());
//        }
//        System.out.println(map.get("桂林一中").getClass());
//        System.out.println(schools.getClass());
//        for(String school:schools){
//            System.out.println(school);
//        }
        return map;
    }
    //生成学校的列表（List实现
    public static List<String> schoolsList(Map<String,List<Student>> map){
        List<String> schools=new ArrayList<>();
        Iterator<String> iterator = map.keySet().iterator();
        for (Map.Entry<String, List<Student>> entry : map.entrySet()) {
            //result.add(entry.getValue());
            schools.add(iterator.next());
        }
        return schools;
    }
    //将抽取到的学生map集合转成list集合（我还没试过能不能用，导出的人可以先试着用看看行不行
    public static List<Student> selectedStudentMapToList(Map<String,List<Student>> selectedStudent){
        List<Student> students = new ArrayList<>();
        for (Map.Entry<String, List<Student>> entry : selectedStudent.entrySet()) {
            for(Student student:entry.getValue()){
                students.add(student);
            }
        }
        return students;
    }
}
